package com.dingwei.superiordiary.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.TipTypeBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.net.URL;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by lihao on 2017/9/12.
 */

public class ReportPresenter extends basePresenter {

    private Contract.ReportView reportView;

    public ReportPresenter(Contract.ReportView view) {
        super(view);
        this.reportView = view;
    }


    public void initType() {

        RequestParams rp = new RequestParams(URLS.HOST + URLS.TIP_TYPE);
        rp.addBodyParameter("sessionid",BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, TipTypeBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                TipTypeBean bean = (TipTypeBean) baseBean;
                reportView.getData(bean);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });

    }

    public void tip(String id, String type, String content,String tip_type) {

        if (TextUtils.isEmpty(type)) {
            showToast("请选择举报类型");
            return;
        }

        RequestParams rp = new RequestParams(URLS.HOST+ URLS.tipComment);
        if (!TextUtils.isEmpty(tip_type)&&tip_type.equals("goods")){
            rp = new RequestParams(URLS.HOST+ URLS.TIP_GOODS);
            rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
            rp.addBodyParameter("id",id);
            rp.addBodyParameter("type",type);
            rp.addBodyParameter("content",content);
        }
        if (!TextUtils.isEmpty(tip_type)&&tip_type.equals("tie")){
            rp = new RequestParams(URLS.HOST+ URLS.TIP);
            rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
            rp.addBodyParameter("id",id);
            rp.addBodyParameter("type",type);
            rp.addBodyParameter("content",content);
        }
        if (!TextUtils.isEmpty(tip_type)&&tip_type.equals("user")){
            rp = new RequestParams(URLS.HOST+ URLS.TIP_u);
            rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
            rp.addBodyParameter("memberid",id);
            rp.addBodyParameter("type",type);
            rp.addBodyParameter("content",content);
        }
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast(baseBean.message);
                reportView.tipSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
